home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 June / EnigmA AMIGA RUN 19 (1997)(G.R. Edizioni)(IT)[!][issue 1997-06][EAR-CD III].iso / recent1 / apic1805.lha / APIC / examples / mouse12.lha / mouse.src < prev    next >
Text File  |  1997-05-10  |  8KB  |  500 lines

  1. ;PC mouse adapter for Amiga computers
  2. ;
  3. ; use serial Pc mouse on Amiga Computers without Software driver !!
  4. ;
  5. ; 03.01.96
  6. ;
  7. ;This Program converts the microsoft and the mouse system format to amiga ones,
  8. ;three mouse buttons are supported (mouse system).
  9. ;Only hardware, it`s like an original Amiga mouse
  10. ;The Xtal frequenzy is 11.0592 Mhz, the TXD line from mouse is with a 20K
  11. ;resistor directly with the PIC 16C54 Port connected. Only three other components
  12. ;are needed for the voltage conversion: ICL7660 (voltage converter from Harris 
  13. ;semiconductor,INTERSIL) and two capacitors with 10µF. The PCB is about 3*4.5cm.
  14. ;My PC mouse needs -5V on TXD,5V on RTS and ground. 
  15. ;The adapter recognizes mouse protocoll changes automatic. I think it`s easy
  16. ;to include the Logitech protokoll but I don`t know it.
  17. ;
  18. ; see our Amiga Pic Tools Home Page:
  19. ;
  20. ; http://linux.rz.fh-hannover.de/~duesterb/
  21. ; (Pic Simulator, Pic Progger)
  22. ;
  23. ;Dirk Düsterberg, duesterb@unixserv.rz.fh-hannover.de
  24. ;
  25. ;Jahnstr.9
  26. ;31860 Emmerthal
  27. ;Germany
  28. ;
  29. ;
  30. ;thanks to Joannis Petroglou, who made this with his wonderful Tools possibel!
  31.  
  32.  
  33.  
  34. ; Microsoft is a registered trademark of Microsoft Corp.
  35. ; Mouse Systems is  registered trademark of MSC Technologies, Inc.
  36. ; Microchip is a registered trademark of Microchip Technology
  37. ; Logitech is a registered trademark too
  38. ; This source is copyrighted to Dirk Düsterberg, no trademark
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.     list p=PIC16C54, r=hex, s=off
  46.  
  47.     RESET    start
  48.  
  49.  
  50.     CBLOCK 08h
  51.       trycnt            ;synctrys, which format?
  52.       loopcnt            ;loop counter
  53.       bitcnt            ;bit counter
  54.       serbuf            ;serial buffer
  55.       RBbuf                ;Port buffer
  56.     ENDC
  57.  
  58.     CBLOCK    10h
  59.       byte0                ;first received byte
  60.       byte1                ;second received byte and byte 4 (mouse system)
  61.       byte2                ;third received byte and byte 5 (mouse system)
  62.     ENDC
  63.  
  64. RA    =    5
  65. RB    =    6
  66.  
  67.  
  68.  
  69. #define    RXD    RA,1            ;RXD input, bit 1 from Port A
  70.  
  71. #define    r_b    RBbuf,2            ;right mouse button
  72. #define    m_b    RBbuf,4            ;middle mouse button
  73. #define    l_b    RBbuf,6            ;left mouse button
  74.  
  75. #define    H    RBbuf,0            ;Horizontal Pulses
  76. #define    HQ    RBbuf,5            ;Horizontal Quadrature Pulses
  77. #define    V    RBbuf,1            ;Vertical Pulses
  78. #define    VQ    RBbuf,7            ;Vertical Quadrature Pulses
  79.  
  80.  
  81. #define    c    03,0
  82. #define    z    03,2
  83.  
  84.  
  85. start    movlw    0
  86.     tris    RB
  87.  
  88.     movlw    0ffh
  89.     tris    RA
  90.  
  91.     clrf    RBbuf            ;make butoons unpressed
  92.     decf    RBbuf,f
  93.  
  94.     movf    RBbuf,w            ;use Port buffer to prevent read from Port
  95.     movwf    RB
  96.  
  97.     clrf    trycnt,f
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. ;this is the routine for the microsoft format (3 bytes with 2 buttons)
  110.  
  111.  
  112.  
  113. micro    clrf    trycnt,f
  114. mic    movlw    .4
  115.     subwf    trycnt,w
  116.     btfsc    c
  117.     goto    mouse            ;more than 3 trys? jump!
  118.     
  119.     call    rcb            ;receive the first byte
  120.     incf    trycnt,f
  121.     
  122.     movf    serbuf,w
  123.     xorlw    11000000b        ;invert bit 6 and 7 from working register
  124.     andlw    11000000b        ;clr bit 0 to 5 (buttons and coord.)
  125.     btfss    z            ;skip if w is zero
  126.     goto    mic            ;if not zero -> no match
  127.  
  128.     movf    serbuf,w        ;this is the first received byte
  129.     movwf    byte0
  130.  
  131.     bsf    m_b            ;middle button not supported
  132.  
  133.     btfsc    serbuf,4        ;mov buttons
  134.     bcf    r_b
  135.     btfss    serbuf,4
  136.     bsf    r_b
  137.  
  138.     btfsc    serbuf,5
  139.     bcf    l_b
  140.     btfss    serbuf,5
  141.     bsf    l_b
  142.  
  143.     call    rcb            ;receive second byte
  144.  
  145.     
  146.     movlw    10000000b
  147.     xorwf    serbuf,f        ;invert bit 7 from buffer
  148.     movf    serbuf,w
  149.     andlw    11000000b        ;clr bit 0 to 5 (coord.)
  150.     btfss    z                ;skip if w is zero
  151.     goto    mouse            ;if not zero -> no match -> mouse format
  152.         
  153.     
  154.     clrf    byte1
  155.  
  156.     btfss    byte0,0            ;mov x6 and x7 coord. to byte1
  157.     bcf    byte1,6
  158.     btfsc    byte0,0
  159.     bsf    byte1,6
  160.  
  161.  
  162.     btfss    byte0,1            ;mov x6 and x7 coord. to byte1
  163.     bcf    byte1,7
  164.     btfsc    byte0,1
  165.     bsf    byte1,7
  166.  
  167.  
  168.  
  169.     movf    serbuf,w        ;set rest of x coord.
  170.     iorwf    byte1,f
  171.  
  172.  
  173.  
  174.     call    rcb            ;receive third byte
  175.  
  176.  
  177.     movlw    10000000b
  178.     xorwf    serbuf,f        ;invert bit 7 from buffer
  179.     movf    serbuf,w
  180.     andlw    11000000b        ;clr bit 0 to 5 (coord.)
  181.     btfss    z            ;skip if w is zero
  182.     goto    mouse            ;if not zero -> no match -> mouse format
  183.  
  184.     clrf    byte2
  185.  
  186.  
  187.  
  188.     btfss    byte0,2            ;mov y6 and y7 coord. to byte2
  189.     bcf    byte2,6
  190.     btfsc    byte0,2
  191.     bsf    byte2,6
  192.  
  193.  
  194.  
  195.     btfss    byte0,3            ;mov y6 and y7 coord. to byte2
  196.     bcf    byte2,7
  197.     btfsc    byte0,3
  198.     bsf    byte2,7
  199.  
  200.  
  201.  
  202.     movf    serbuf,w        ;set rest of y coord.
  203.     iorwf    byte2,f
  204.  
  205.     comf    byte2,f            ;fix microsoft to mouse protokoll
  206.     incf    byte2,f            ;(up and down exchanged)
  207.  
  208.     clrf    trycnt
  209.     goto    micro
  210.  
  211.  
  212.  
  213. ;this is the routine for the mouse system format (5 bytes with 3 buttons)
  214.  
  215.  
  216. mouse    movlw    .6
  217.     subwf    trycnt,w
  218.     btfsc    c
  219.     goto    micro            ;more than 5 trys? jump micro!
  220.  
  221.     call    rcb            ;get first of five bytes from serial mouse
  222.  
  223.     incf    trycnt,f        ;one more try
  224.  
  225. ;test format #10000lmr (left, middle, right) 
  226.  
  227.     movf    serbuf,w
  228.     xorlw    10000000b        ;invert bit 7 from working register
  229.     andlw    11111000b        ;clr bit 0 to 2 (buttons)
  230.     btfss    z            ;skip if w is zero
  231.     goto    mouse            ;if not zero -> no match
  232.     
  233.     movf    serbuf,w
  234.     movwf    byte0
  235.  
  236.  
  237.  
  238.     call    rcb            ;byte1, X-Axis movement data
  239.     movf    serbuf,w
  240.     movwf    byte1
  241.  
  242.     call    rcb            ;byte2, Y-Axis movement data
  243.     movf    serbuf,w
  244.     movwf    byte2
  245.     
  246.     call    rcb            ;byte3, X-Axis movement data    
  247.     movf    serbuf,w
  248.     movwf    byte1
  249.  
  250.     call    rcb            ;byte4, Y-Axis movement data
  251.     movf    serbuf,w
  252.     movwf    byte2
  253.  
  254.  
  255.  
  256.     btfss    byte0,0            ;convert to Amiga
  257.     bcf    r_b
  258.     btfsc    byte0,0
  259.     bsf    r_b
  260.  
  261.  
  262.     btfss    byte0,1
  263.     bcf    m_b
  264.     btfsc    byte0,1
  265.     bsf    m_b
  266.  
  267.  
  268.     btfss    byte0,2
  269.     bcf    l_b
  270.     btfsc    byte0,2
  271.     bsf    l_b
  272.  
  273.  
  274.     movf    RBbuf,w
  275.     movwf    RB            ;use Port buffer to prevent read from Port
  276.  
  277.     clrf    trycnt            
  278.  
  279.     goto    mouse
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287. ;receive routine, receive 8bits
  288. ;loop is done until byte is received
  289.  
  290.  
  291.  
  292.  
  293. rcb    btfsc    RXD
  294.     goto    rcshift            ;startbit ?
  295.     goto    rcb
  296.  
  297. rcshift    movlw    .8
  298.     movwf    bitcnt
  299.  
  300.     call    whbit            ;wait half bit (middle bit position)
  301.  
  302. r_it    call    wbit            ;wait bit delay
  303.  
  304.     btfss    RXD            ;move RXD into c
  305.     bcf    c
  306.     btfsc    RXD
  307.     bsf    c
  308.  
  309.     rrf    serbuf,f        ;rotate c in serbuf
  310.     decfsz    bitcnt
  311.     goto    r_it            ;decrement bit counter (8 bits)
  312.     comf    serbuf            ;invert serbuf (RS232 -> TTL)
  313.     call    whbit            ;wait a half bit to get out from data area
  314.     retlw    0            ;back
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323. ;wait routine for one and one half bit for 1200 baud
  324.  
  325.  
  326. whbit    movlw    .125
  327.     movwf    loopcnt            ;1200
  328. do_hbit    nop
  329.     nop
  330.     nop
  331.     nop
  332.     nop
  333.     nop
  334.     nop
  335.     decfsz    loopcnt
  336.     goto    do_hbit
  337.     retlw    0
  338.  
  339.  
  340.  
  341.  
  342.  
  343. ;this routine is one bit long, it converts the axe counter to a quadrature
  344. ;modulation, every change on V,VQ,H or HQ means a mouse move
  345.  
  346.  
  347. wbit    movlw    .45
  348.     movwf    loopcnt            ;quad mod is done while bit waiting
  349.  
  350. x_axe    movf    byte1,w
  351.     btfsc    z
  352.     goto    x_axe0            ;byte1 = 0, nothing to do
  353.     btfsc    byte1,7
  354.     goto    _right            ;jump if bit
  355.     nop
  356.     nop
  357.     nop
  358.     nop
  359.     nop
  360. left    decf    byte1,f            ;decrement byte 1
  361.     btfsc    H
  362.     goto    leftx1            ;jmp to x1 if H set
  363.     btfsc    HQ
  364.     goto    left10
  365.     bsf    H            ;set H if H and HQ clear
  366.     goto    lback1
  367. leftx1    btfsc    HQ            
  368.     bcf    H            ;clr H if H set and HQ set
  369.     btfss    HQ
  370.     bsf    HQ            ;set HQ if H set and HQ clear
  371.     goto    lback3
  372. left10    bcf    HQ            ;clear HQ if H clear and HQ set
  373.     goto    lback2
  374. x_axe0    nop
  375.     nop
  376.     nop
  377.     nop
  378.     nop
  379.     nop
  380.     nop
  381.     nop
  382.     nop
  383.     nop
  384.     nop
  385.     nop
  386.     nop
  387.     nop
  388. lback1    nop
  389. lback2    nop
  390. lback3    movf    RBbuf,w
  391.     movwf    RB            ;use Port buffer to prevent read from Port
  392.     goto    y_axe
  393.  
  394. _right    comf    byte1,f            ;negate byte1
  395.     incf    byte1,f
  396.  
  397.     nop
  398.     nop
  399.  
  400. right    decf    byte1,f
  401.     btfsc    HQ
  402.     goto    right1x            ;jmp to 1x if HQ set
  403.     btfsc    H
  404.     goto    right01
  405.     bsf    HQ            ;set HQ if H and HQ clear
  406.     goto    rback1
  407. right1x    btfsc    H            
  408.     bcf    HQ            ;clrb H if H and HQ set
  409.     btfss    H
  410.     bsf    H            ;setb H if H clear and HQ set
  411.     goto    rback3
  412. right01    bcf    H            ;clr H if HQ clear and H set
  413.     goto    rback2
  414.  
  415. rback1    nop
  416. rback2    nop
  417. rback3    movf    RBbuf,w
  418.     movwf    RB            ;use Port buffer to prevent read from Port
  419.     comf    byte1,f
  420.     incf    byte1,f
  421.  
  422.     
  423.  
  424.  
  425. y_axe    movf    byte2,w
  426.     btfsc    z
  427.     goto    y_axe0            ;byte2 = 0, nothing to do
  428.     btfsc    byte2,7
  429.     goto    _up            ;jump if bit
  430.     nop
  431.     nop
  432.     nop
  433.     nop
  434.     nop
  435. down    decf    byte2,f
  436.     btfsc    VQ
  437.     goto    down1x            ;jmp to 1x if VQ set
  438.     btfsc    V
  439.     goto    down01
  440.     bsf    VQ            ;set VQ if V and VQ clear
  441.     goto    dback1
  442. down1x    btfsc    V            
  443.     bcf    VQ            ;clrb V if V and VQ set
  444.     btfss    V
  445.     bsf    V            ;setb V if V clear and VQ set
  446.     goto    dback3
  447. down01    bcf    V            ;clr V if VQ clear and V set
  448.     goto    dback2
  449. y_axe0    nop
  450.     nop
  451.     nop
  452.     nop
  453.     nop
  454.     nop
  455.     nop
  456.     nop
  457.     nop
  458.     nop
  459.     nop
  460.     nop
  461.     nop
  462.     nop
  463. dback1    nop
  464. dback2    nop
  465. dback3    movf    RBbuf,w
  466.     movwf    RB            ;use Port buffer to prevent read from Port
  467.     goto    done
  468.  
  469. _up    comf    byte2,f
  470.     incf    byte2,f
  471.     nop
  472.     nop
  473.  
  474. up    decf    byte2,f
  475.     btfsc    V
  476.     goto    up_x1            ;jmp to x1 if V set
  477.     btfsc    VQ
  478.     goto    up_10
  479.     bsf    V            ;set V if V and VQ clear
  480.     goto    uback1
  481. up_x1    btfsc    VQ            
  482.     bcf    V            ;clr V if V set and VQ set
  483.     btfss    VQ
  484.     bsf    VQ            ;set VQ if V set and VQ clear
  485.     goto    uback3
  486. up_10    bcf    VQ            ;clear VQ if V clear and VQ set
  487.     goto    uback2
  488. uback1    nop
  489. uback2    nop
  490. uback3    movf    RBbuf,w
  491.     movwf    RB            ;use Port buffer to prevent read from Port
  492.     comf    byte2,f
  493.     incf    byte2,f
  494.     
  495.     
  496.  
  497. done    decfsz    loopcnt
  498.     goto    x_axe
  499.     retlw    0    
  500.